package homework_java.shape;
import java.util.HashMap;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

class Course {
    String key;
    String name;
    int learn;
    Course() {}
    Course(String a, String b, int c) {
        this.key = a;
        this.name = b;
        this.learn = c;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(this.key).toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        Course p = (Course) obj;
        return new EqualsBuilder().append(this.key, p.key)/* .append(this.name, p.name) */
                .isEquals();

    }
    @Override
    public String toString() {
        return "name:"+this.name+",learn:"+this.learn;
    }
}

    class CourseMap {
        HashMap<String, Course> map = new HashMap<String, Course>();

        public boolean addC(Course o) {
            if (map.containsKey(o.key))
                return false;
            else {
                map.put(o.key, o);
                return true;
            }
        }

        public boolean removeC(Course o) {
            if (!map.containsKey(o.key)) // 判断字符串是否有字串
            {
                System.out.println("不存在");
                return false;
            } else {
                map.remove(o.key);
                System.out.println("已删除");
                return true;
            }
        }
        public void display(){
            System.out.println(map);
        }

  /*  public  <T1, T2> void traverseMapViaIterator(Map<T1, T2> map){
		System.out.println("***Iterator***");
		int i = 0;
		for(Iterator<Entry<T1, T2>> it = map.entrySet().iterator(); it.hasNext();){			
			//System.out.println((++i) + ": " + it.next());			
			Entry<T1, T2> entry = it.next();
			System.out.print((++i) + ": ");
			System.out.print("key = " + entry.getKey() + ", ");
			System.out.println("value = " + entry.getValue());
			
		}
	}*/
}
public class TestCourseMap {
    public static void main(String[] args) {
        Course c= new Course("3","jiekou",92);
        CourseMap ss=new CourseMap();
        ss.addC(new Course("1","java",42));
        ss.addC(new Course("2","huibian",32));
        ss.addC(c);
        ss.addC(new Course("4","wangluo",12));
        ss.display();
        ss.removeC(c);
        ss.display();


    }
}

